package com.service.zy;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.dao.zy.PurchaseDao;
import com.entity.Purchase;
import com.service.ServiceException;

@Service
@Transactional(rollbackFor=ServiceException.class)
public class PurchaseService {
	@Autowired
	private PurchaseDao purchaseDao;
	
	/**
	 * 添加一个采购单
	 * @param purchase
	 * @throws ServiceException
	 */
	public void add(Purchase purchase) throws ServiceException {
		try {
			purchaseDao.save(purchase);
		}catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	
	/**
	 * 删除一个采购单
	 * @param id
	 * @throws ServiceException
	 */
	public void delete(Long id) throws ServiceException {
		try {
			purchaseDao.delete(id);
		}catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	
	/**
	 * 查询所有采购单
	 * @return
	 * @throws ServiceException
	 */
	public List<Purchase> findAll() throws ServiceException {
		try {
			return (List<Purchase>) purchaseDao.findAll();
		}catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	
	/**
	 * 查询一个采购单
	 * @param id
	 * @return
	 * @throws ServiceException
	 */
	public Purchase findOne(Long id) throws ServiceException {
		try {
			return purchaseDao.findOne(id);
		}catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	
}
